﻿using MiniFox.Components;
using MiniFox.Platform.State;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Platform.Applications.Auth
{
    /// <summary>
    /// 
    /// </summary>
    [AutoRegister, SpareComponent(typeof(AuthStateManagement))]
    public interface IAuthStateManagement : IClientStateManagement
    {
        /// <summary>
        /// 
        /// </summary>
        string Token
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        SystemIdentity CurrentIdentity
        {
            get;
            set;
        }
        /// <summary>
        /// 
        /// </summary>
        ClaimsPrincipal CurrentPrincipal { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class AuthStateManagement : ClientStateManagement, IAuthStateManagement
    {
        /// <summary>
        /// jwt token
        /// </summary>
        public string Token { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public virtual SystemIdentity CurrentIdentity { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public ClaimsPrincipal CurrentPrincipal { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public override void Clear()
        {
            this.CurrentIdentity = null;
            this.Token = null;
            this.Cleared = true;
        }
    }
}
